﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CourseRecommend
{
    public partial class HomeForm : Form
    {
        public static int semesterHours;
        public static int selectedSwapIndex =0;
        public static string startSem;
        public static int semInt = 0;
        public static Boolean summer = false;
        public static Boolean hasSwapped = false;
        public static List<string> tempRecommendedList = new List<string>();
        
        public HomeForm()
        {
            InitializeComponent();
        }
        private void AddEditButton_Click(object sender, EventArgs e)
        {
            Form AddForm = new AddForm();
            AddForm.Show();
            AddForm.Activate();
            this.Hide();
        }

        private void RecommendButton_Click(object sender, EventArgs e)
        {
            // clear evertything for multiple recommendations
            listBox1.Items.Clear();
            RecommendMe.recommendedList.Clear();
            RecommendMe.tempHistoryList.Clear();
            RecommendMe.classNames.Clear();
            RecommendMe.creditList.Clear();
            RecommendMe.prereqList.Clear();
            RecommendMe.prereqNotTaken.Clear();
            RecommendMe.prereqsToTake.Clear();
            RecommendMe.semesterCount = 0;
            RecommendMe.orderedCurriculum.Clear();
            RecommendMe.historyList.Clear();
            RecommendMe.semesterCount = 0;
            getSemester();

            // make recommendations
            RecommendMe.getHistory();
            RecommendMe.getOrderedList();
            RecommendMe.recommendSchedule();

            foreach (string item in RecommendMe.classNames)
            {
                listBox1.Items.Add(item);
            }

            string[] semArray = new string[3] { "Spring", "Summer", "Fall" };

            try
            {
                if (summerCheck.Checked)
                    dateLabel.Text = semArray[RecommendMe.currentSemester -1] + " " + (Convert.ToInt32(yearBox.Text) + RecommendMe.semesterCount / 3).ToString();
                else
                    dateLabel.Text = semArray[RecommendMe.currentSemester -1] + " " + (Convert.ToInt32(yearBox.Text) + RecommendMe.semesterCount / 2).ToString();
            }
            catch (Exception nullE)
            {
                MessageBox.Show("You must choose a starting semester");
                MessageBox.Show(nullE.ToString());
                listBox1.Items.Clear();
            }
        }


        private void creditBox_TextChanged(object sender, EventArgs e)
        {
            try
            {
                semesterHours = Convert.ToInt32(creditBox.Text);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
        }

        private void HomeForm_Load(object sender, EventArgs e)
        {
            semesterHours = Convert.ToInt32(creditBox.Text);
            getSemester();
            if (hasSwapped)
            {
                foreach (string item in RecommendMe.classNames)
                {
                    listBox1.Items.Add(item);
                }
            }
            //listBox1.View = View.Details;
            //listBox1.HeaderStyle = ColumnHeaderStyle.None;
            //ColumnHeader h = new ColumnHeader();
            //h.Width = listBox1.ClientSize.Width - SystemInformation.VerticalScrollBarWidth;
            //listBox1.Columns.Add(h);


          
        }

        public void getSemester()
        {
            startSem = semesterBox.Text;
            summer = summerCheck.Checked;
            switch (startSem)
            {
                case ("Spring"):
                    semInt = 1;
                    break;
                case ("Summer"):
                    semInt = 2;
                    break;
                case ("Fall"):
                    semInt = 3;
                    break;
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void SwapButton_Click(object sender, EventArgs e)
        {
            //string selected;
            
            //try
            //{
            //    selected = listBox1.SelectedItems.ToString();
            //    selectedSwapIndex = listBox1.SelectedIndices[0];
            //    ClearAfterSwapIndex();
                
            //}
            //catch (Exception notSelected)
            //{
            //    MessageBox.Show("Select a class before pressing swap");
            //}
            //RecommendMe.tempHistoryList.Clear();
            //RecommendMe.historyList.Clear();
            //RecommendMe.orderedCurriculum.Clear();
            //RecommendMe.recommendedList.Clear();
            //RecommendMe.getHistory();
            //RecommendMe.tempHistoryList = RecommendMe.historyList;
            //for (int k = 0; k < selectedSwapIndex; k++)
            //{
            //    RecommendMe.tempHistoryList.Add(listBox1.Items[k].ToString());
            //    RecommendMe.historyList.Add(listBox1.Items[k].ToString());
            //    tempRecommendedList.Add(listBox1.Items[k].ToString());
            //}
            //Form SwapForm = new SwapForm();
            //SwapForm.Show();
            //SwapForm.Activate();
            //this.Close();
            //RecommendMe.classNames.Clear();
            MessageBox.Show("Coming Soon!", "Please excuse our construction");

        }

        private void ClearAfterSwapIndex()
        {
            int itemCount = listBox1.Items.Count;
            List<string> tempListBoxList = new List<string>();
            RecommendMe.tempHistoryList.Clear();

            for (int i = 0; i < selectedSwapIndex; i ++)
            {
                tempListBoxList.Add(listBox1.Items[i].ToString());
                if(! listBox1.Items[i].ToString().Contains("\r\n"))
                RecommendMe.tempHistoryList.Add(listBox1.Items[i].ToString());
            }
            listBox1.Items.Clear();
            foreach (string item in tempListBoxList)
                listBox1.Items.Add(item);
        }

        private void RemoveButton_Click(object sender, EventArgs e)
        {
           // ClearAfterSwapIndex();
            MessageBox.Show("Coming Soon!", "Please excuse our construction");

        }
        public void repopulateListbox()
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
